package chapter4.No4_1_使用reentrantLock类.demo8;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * *：
 * 自己的思路实现的生产者/消费者模式
 *
 * @author liujian
 * @version 2016/11/21 0021
 */
public class Main {
    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();
        Condition conditionP = lock.newCondition();
        Condition conditionC = lock.newCondition();
        P p = new P(lock, conditionP, conditionC);
        C c = new C(lock, conditionP, conditionC);
        ThreadP[] ps = new ThreadP[10];
        ThreadC[] cs = new ThreadC[10];
        for (int i = 0; i < 10; i++) {
            ps[i] = new ThreadP(p);
            cs[i] = new ThreadC(c);
            ps[i].start();
            cs[i].start();
        }
    }
}
